"""
发布相关的Pydantic schema
"""
from pydantic import BaseModel, Field
from typing import List, Optional, Dict, Any
from datetime import datetime


class PublishToDraftRequest(BaseModel):
    """发布到草稿箱请求模型"""
    article_id: str = Field(..., description="文章ID")
    author: Optional[str] = Field("", description="作者名称")
    content_source_url: Optional[str] = Field("", description="原文链接")
    show_cover_pic: bool = Field(True, description="是否显示封面图")
    need_open_comment: bool = Field(False, description="是否开启评论")
    only_fans_can_comment: bool = Field(False, description="仅粉丝可评论")


class PublishToDraftResponse(BaseModel):
    """发布到草稿箱响应模型"""
    success: bool
    message: str
    draft_id: Optional[str] = None
    article_id: str


class DraftInfo(BaseModel):
    """草稿信息模型"""
    media_id: str
    update_time: datetime
    content: Dict[str, Any]

    class Config:
        json_encoders = {
            datetime: lambda v: v.isoformat()
        }


class DraftListResponse(BaseModel):
    """草稿列表响应模型"""
    items: List[DraftInfo]
    total_count: int


class MaterialInfo(BaseModel):
    """素材信息模型"""
    media_id: str
    name: str
    update_time: datetime
    url: Optional[str] = None

    class Config:
        json_encoders = {
            datetime: lambda v: v.isoformat()
        }


class MaterialListResponse(BaseModel):
    """素材列表响应模型"""
    items: List[MaterialInfo]
    total_count: int
    item_count: int


class PublishHistoryResponse(BaseModel):
    """发布历史响应模型"""
    article_id: str
    title: str
    draft_id: Optional[str]
    published_at: Optional[datetime]
    status: str
    theme_name: Optional[str]

    class Config:
        json_encoders = {
            datetime: lambda v: v.isoformat()
        }